<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-jmeterJarMgt-add">
			<div class="form-group">
				<label class="col-sm-3 control-label">jar包名称（包含版本）：</label>
				<div class="col-sm-8">
					<input id="name" name="name" class="form-control" type="text">
					<div class="form-group" >
						<label style="display: inline-flex; margin-left: 15px" >
							<input type="file" name="file" id="file" >
							<input type="button" id="uploadBtn" th:value="开始上传" onclick="startUpload()">
						</label>
					</div>
				</div>
			</div>

			<label class="col-sm-3 control-label">是否全局：</label>
			<div class="radio-box">
				<input type="radio" id="global_yes" name="global" value="1" checked="true"  >
				<label style="color:#dc952c" th:text="全局" ></label>
			</div>
			<div class="radio-box">
				<input type="radio" id="global_no" name="global" value="0" >
				<label style="color:#2b31dc" th:text="关联测试用例"></label>
			</div>


			<div class="form-group" id="case-select-dev" style="display: none">
				<label class="col-sm-3 control-label">选择测试用例</label>
				<div class="col-sm-8">
					<select id="relCaseIdList" name="relCaseIdList" class="form-control m-b" multiple="multiple">
						<option value="" >请选择</option>
						<option th:each="item:${cases}" th:text="${item.caseName}" th:value="${item.id}" ></option>
					</select>
				</div>
			</div>


			<input type="hidden" id="location" name="location" class="form-control" />

			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="remark" name="remark" class="form-control" type="text">
				</div>
			</div>


		</form>
	</div>


    <div th:include="include::footer"></div>
	<script th:src="@{/ajax/libs/select/select2.js}"></script>
	<script type="text/javascript">
		var prefix = ctx + "jmeter/jmeterJarMgt"
		$("#form-jmeterJarMgt-add").validate({
			rules:{
				xxxx:{
					required:true,
				},
			}
		});

		//save
		function submitHandler() {
			if ($.validate.form()) {
				let  data = $('#form-jmeterJarMgt-add').serializeObject();
				let idList = data.relCaseIdList;
				if(!Array.isArray(idList)){
					data.relCaseIdList=[];
					data.relCaseIdList.push(idList);
				}

				$.operate.saveJson(prefix + "/add", JSON.stringify(data));
			}
		}

		function startUpload() {
			var drivenfile = $('#file')[0].files[0];

			if(drivenfile==undefined){
				$.modal.msgError("jar文件");
				return;
			}

			var formData = new FormData();
			formData.append("file", drivenfile);
			$.ajax({
				url: prefix + "/uploadJar",
				type: 'POST',
				cache: false,
				data: formData,
				processData: false,
				contentType: false,
				success: function (result) {
					if (result.code == web_status.SUCCESS) {
						$("#name").val(drivenfile.name);
						$("#location").val(result.path);
						$.modal.msgSuccess(result.msg);
					} else {
						$.modal.msgError(result.msg);
					}
				}
			});
		}


		$(document).ready(function () {
			// 方法名称：获取当前选中的值；icheck-radio change事件；点击事件;
			$("input:radio[name='global']").on('ifChecked', function(event){
				let val = $(this).val();
				if(val==1){
					$("#case-select-dev").slideUp();
				}

				if(val==0){
					$("#case-select-dev").slideDown();
				}
			});

			$("#relCaseIdList").select2();
		})
	</script>
</body>
</html>
